<?php
class FormProcessor_RemarkEdit extends FormProcessor {
	public $remark;
	public $article;
	public $user;
	public $db;
	
	public function __construct($db, $userid, $articleid) {
		parent::__construct($db);
		$this->db = $db;
		$this->remark = new DatabaseObject_Remark($this->db);
		
		$this->user = new DatabaseObject_User($this->db);
		if (!$this->user->load($userid)) {
			$this->hasError('title', '用户验证失败');
		}
		
		$this->article = new DatabaseObject_Article($this->db);
		if (!$this->article->load($articleid)) {
			$this->hasError('title', '文章验证失败');
		}
	}
	
	public function process(Zend_Controller_Request_Abstract $request) {
		$this->content = $this->sanitize($request->getPost('content'));
		
		if (strlen($this->content) == 0) {
			$this->hasError('content', '评论内容不能为空');
		} else {
			$this->remark->content = $this->content;
		}
		
		if(!$this->hasError()) {
			$this->remark->dateline = time();
			$this->remark->articleid = $this->article->getId();
			$this->remark->userid = $this->user->getId();
			$this->remark->username = $this->user->username;
			$this->remark->save();
		}
		
		return !$this->hasError();
		
	}
}
?>